---@class RedRob.ReportMgr
local ReportMgr = RedRob.CreateClass("ReportMgr")
ReportMgr.isPrint = false
ReportMgr.isTrace = false
local this = ReportMgr

function ReportMgr.OnCreate()
end
function ReportMgr.OnDestroy()
end
function ReportMgr.Record(frame, deltaTime)

end
function ReportMgr.GetTimeStr()
    return os.date("%H:%M:%S   ",os.time())
end
function ReportMgr.Print(...)
    if not this.isPrint then
        return
    end
    if this.isTrace then
        this.PrintTrace(...)
    else
        local str = ""
        for i = 1, select('#', ...) do
            str = str .. tostring(select(i, ...)) .. '\t'
        end
        str = "f:"..RedRob.ClientBattle.frameCount .." t:"..RedRob.ClientBattle.deltaTime.." " ..str
        Util.WriteToFileAsync("report.txt",str,true)
    end

end
function ReportMgr.PrintTrace(...)
    if not this.isPrint then
        return
    end
    local str = ""
    for i = 1, select('#', ...) do
        str = str .. tostring(select(i, ...)) .. '\t'
    end
    str = debug.traceback(str)
    Util.WriteToFileAsync("report.txt",str,true)
end

function ReportMgr.RecordMsg(msg,name)
    if not this.isPrint then return end
    local m = this.clone(msg)
    m._uniqueName = name
    this.Print(getJsonStr(m))
    TablePool.Release(m)
end
function ReportMgr.clone(object)
    local lookup_table = TablePool.Get()
    local function _copy(object)
        if type(object) ~= "table" then
            if type(object) == "userdata" then
                return tostring(object)
            else
                return object
            end
        elseif lookup_table[object] then
            return lookup_table[object]
        end
        local new_table = TablePool.Get()
        lookup_table[object] = new_table
        for key, value in pairs(object) do
            new_table[_copy(key)] = _copy(value)
        end
        return setmetatable(new_table, getmetatable(object))
    end
    local cy = _copy(object)
    TablePool.ReleaseDeeper(lookup_table,false)
    return cy
end